package net.magicalcloud.magicalcloud.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.magicalcloud.magicalcloud.R;
import net.magicalcloud.magicalcloud.base.BaseViewHolder;
import net.magicalcloud.magicalcloud.entity.Files;
import net.magicalcloud.magicalcloud.listener.OnRecyclerViewListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 回收站适配器
 * Created by zhy on 2018/6/8.
 */

public class RecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<Files> data=new ArrayList<>();

    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    public void setData(List<Files> data) {
        this.data.clear();
        if(data!=null){
            this.data.addAll(data);
        }
        notifyDataSetChanged();
    }

    public Files getItem(int position){
        return this.data == null?null:(position >= this.data.size()?null:this.data.get(position));
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new FileViewHolder(parent.getContext(),parent,onRecyclerViewListener);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        //绑定数据
        ((BaseViewHolder)holder).bindData(data.get(position));

    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }
}
